﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;

namespace Metro.Kashikoi.ServiceContract.Location
{
    /// <summary>
    /// This class defines the unit.
    /// </summary>
    [DataContract(IsReference = true)]
    public class Unit : Region
    {
        /// <summary>
        /// Gets or sets the facility.
        /// </summary>
        /// <value>
        /// The facility.
        /// </value>
        [NotMapped]
        public Facility Facility
        {
            get { return this.Parent as Facility; }
            set { this.Parent = value; }
        }

        /// <summary>
        /// Gets or sets the stock areas.
        /// </summary>
        /// <value>
        /// The stock areas.
        /// </value>
        [NotMapped]
        public IEnumerable<StockArea> StockAreas
        {
            get
            {
                if (this.Children != null)
                {
                    return this.Children.OfType<StockArea>();
                }
                return null;
            }
            set
            {
                if (this.Children == null)
                {
                    this.Children = new List<Region>();
                }
                foreach (var item in value)
                {
                    this.Children.Add(item);
                }
            }
        }
    }
}
